/**
 * Copyright 2019-2020 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>

#include "common/formats/format_transfers/format_transfer_nc1hwc0_nhwc.h"

#include "common/formats/format_transfers/format_transfer.h"
#include "common/fp16_t.h"

namespace ge {
namespace formats {
class UtestFormatTransfer5dNhwc : public testing::Test {
 protected:
  void SetUp() {}
  void TearDown() {}
};

TEST_F(UtestFormatTransfer5dNhwc, nc1hwc0_to_nhwc_uint8) {
  uint8_t data[1 * 4 * 4 * 3] = {
      2,  6,  1, 6, 11, 12, 30, 24, 4,  28, 22, 25, 20, 5,  18, 15, 23, 27, 1,  25, 26, 24, 11, 8,
      21, 15, 6, 5, 23, 17, 11, 18, 21, 24, 14, 20, 19, 12, 23, 16, 3,  9,  10, 3,  15, 31, 18, 9,
  };

  uint8_t data_5d[1 * 1 * 4 * 4 * 32] = {
      2,  6,  1,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      6,  11, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      30, 24, 4,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      28, 22, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      20, 5,  18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      15, 23, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      1,  25, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      24, 11, 8,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      21, 15, 6,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      5,  23, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      11, 18, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      24, 14, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      19, 12, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      16, 3,  9,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      10, 3,  15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      31, 18, 9,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  };

  TransArgs args{data_5d, FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 32}, {1, 4, 4, 3}, DT_UINT8};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), SUCCESS);
  EXPECT_EQ(result.length, sizeof(data));
  for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
    EXPECT_EQ((reinterpret_cast<uint8_t *>(result.data.get()))[i], data[i]);
  }
}

TEST_F(UtestFormatTransfer5dNhwc, nc1hwc0_to_nhwc_uint8_32c) {
  uint8_t data[1 * 4 * 4 * 32] = {
      21, 14, 25, 9,  25, 3,  8,  21, 13, 29, 15, 6,  9,  30, 2,  9,  10, 25, 10, 3,  10, 21, 28, 31, 5,  6,  9,
      18, 5,  16, 28, 21, 3,  1,  25, 5,  20, 25, 2,  21, 11, 19, 12, 7,  25, 6,  26, 17, 2,  31, 26, 23, 28, 23,
      4,  12, 0,  6,  16, 29, 18, 2,  27, 21, 14, 15, 27, 14, 30, 4,  28, 26, 6,  21, 8,  28, 4,  20, 20, 14, 14,
      21, 15, 14, 2,  0,  3,  21, 22, 28, 23, 2,  23, 23, 17, 6,  17, 5,  28, 23, 6,  2,  0,  26, 3,  24, 30, 9,
      23, 24, 5,  12, 27, 14, 5,  30, 20, 20, 23, 12, 6,  24, 11, 16, 13, 19, 18, 16, 12, 5,  23, 15, 29, 31, 2,
      17, 6,  28, 27, 9,  18, 7,  19, 10, 28, 14, 28, 16, 17, 8,  18, 7,  16, 0,  24, 26, 9,  10, 8,  26, 23, 4,
      21, 21, 13, 9,  24, 13, 0,  6,  10, 3,  14, 21, 22, 28, 4,  13, 20, 20, 10, 17, 24, 31, 6,  14, 21, 29, 31,
      0,  5,  28, 0,  2,  18, 25, 0,  28, 14, 27, 0,  25, 20, 15, 9,  9,  24, 22, 0,  4,  24, 28, 17, 14, 27, 14,
      30, 10, 8,  30, 29, 23, 11, 9,  23, 17, 7,  31, 22, 12, 6,  9,  10, 15, 12, 14, 11, 12, 19, 19, 29, 9,  21,
      12, 1,  27, 29, 8,  11, 3,  7,  18, 13, 15, 23, 5,  9,  6,  8,  31, 20, 12, 14, 26, 31, 16, 18, 5,  15, 1,
      27, 8,  21, 15, 13, 13, 5,  11, 18, 9,  25, 31, 17, 23, 5,  10, 9,  22, 19, 14, 13, 27, 11, 20, 1,  16, 2,
      12, 2,  11, 28, 20, 9,  2,  31, 9,  7,  3,  16, 26, 7,  21, 11, 24, 25, 5,  7,  28, 19, 6,  6,  4,  0,  6,
      28, 6,  20, 10, 12, 16, 7,  3,  3,  17, 1,  11, 21, 5,  14, 18, 17, 17, 2,  21, 15, 20, 0,  15, 13, 29, 21,
      11, 15, 25, 25, 25, 9,  21, 25, 15, 19, 1,  31, 21, 18, 18, 14, 5,  25, 26, 2,  17, 15, 8,  27, 15, 20, 11,
      30, 27, 1,  3,  0,  22, 8,  11, 1,  24, 29, 28, 24, 31, 15, 31, 8,  15, 8,  0,  0,  20, 19, 21, 21, 20, 25,
      31, 24, 20, 3,  3,  4,  14, 15, 4,  12, 26, 22, 13, 10, 13, 22, 9,  14, 12, 7,  13, 19, 3,  23, 24, 3,  15,
      23, 25, 16, 5,  30, 21, 10, 28, 7,  9,  18, 9,  3,  12, 25, 9,  18, 31, 15, 11, 1,  11, 10, 8,  28, 4,  19,
      27, 22, 17, 10, 23, 25, 2,  19, 16, 2,  19, 28, 25, 24, 2,  2,  4,  17, 4,  12, 26, 4,  25, 31, 27, 31, 14,
      17, 13, 24, 5,  10, 10, 17, 26, 16, 15, 25, 18, 15, 10, 22, 13, 30, 16, 23, 10, 23, 24, 10, 14, 5,  17,
  };

  uint8_t data_5d[1 * 1 * 4 * 4 * 32] = {
      21, 14, 25, 9,  25, 3,  8,  21, 13, 29, 15, 6,  9,  30, 2,  9,  10, 25, 10, 3,  10, 21, 28, 31, 5,  6,  9,
      18, 5,  16, 28, 21, 3,  1,  25, 5,  20, 25, 2,  21, 11, 19, 12, 7,  25, 6,  26, 17, 2,  31, 26, 23, 28, 23,
      4,  12, 0,  6,  16, 29, 18, 2,  27, 21, 14, 15, 27, 14, 30, 4,  28, 26, 6,  21, 8,  28, 4,  20, 20, 14, 14,
      21, 15, 14, 2,  0,  3,  21, 22, 28, 23, 2,  23, 23, 17, 6,  17, 5,  28, 23, 6,  2,  0,  26, 3,  24, 30, 9,
      23, 24, 5,  12, 27, 14, 5,  30, 20, 20, 23, 12, 6,  24, 11, 16, 13, 19, 18, 16, 12, 5,  23, 15, 29, 31, 2,
      17, 6,  28, 27, 9,  18, 7,  19, 10, 28, 14, 28, 16, 17, 8,  18, 7,  16, 0,  24, 26, 9,  10, 8,  26, 23, 4,
      21, 21, 13, 9,  24, 13, 0,  6,  10, 3,  14, 21, 22, 28, 4,  13, 20, 20, 10, 17, 24, 31, 6,  14, 21, 29, 31,
      0,  5,  28, 0,  2,  18, 25, 0,  28, 14, 27, 0,  25, 20, 15, 9,  9,  24, 22, 0,  4,  24, 28, 17, 14, 27, 14,
      30, 10, 8,  30, 29, 23, 11, 9,  23, 17, 7,  31, 22, 12, 6,  9,  10, 15, 12, 14, 11, 12, 19, 19, 29, 9,  21,
      12, 1,  27, 29, 8,  11, 3,  7,  18, 13, 15, 23, 5,  9,  6,  8,  31, 20, 12, 14, 26, 31, 16, 18, 5,  15, 1,
      27, 8,  21, 15, 13, 13, 5,  11, 18, 9,  25, 31, 17, 23, 5,  10, 9,  22, 19, 14, 13, 27, 11, 20, 1,  16, 2,
      12, 2,  11, 28, 20, 9,  2,  31, 9,  7,  3,  16, 26, 7,  21, 11, 24, 25, 5,  7,  28, 19, 6,  6,  4,  0,  6,
      28, 6,  20, 10, 12, 16, 7,  3,  3,  17, 1,  11, 21, 5,  14, 18, 17, 17, 2,  21, 15, 20, 0,  15, 13, 29, 21,
      11, 15, 25, 25, 25, 9,  21, 25, 15, 19, 1,  31, 21, 18, 18, 14, 5,  25, 26, 2,  17, 15, 8,  27, 15, 20, 11,
      30, 27, 1,  3,  0,  22, 8,  11, 1,  24, 29, 28, 24, 31, 15, 31, 8,  15, 8,  0,  0,  20, 19, 21, 21, 20, 25,
      31, 24, 20, 3,  3,  4,  14, 15, 4,  12, 26, 22, 13, 10, 13, 22, 9,  14, 12, 7,  13, 19, 3,  23, 24, 3,  15,
      23, 25, 16, 5,  30, 21, 10, 28, 7,  9,  18, 9,  3,  12, 25, 9,  18, 31, 15, 11, 1,  11, 10, 8,  28, 4,  19,
      27, 22, 17, 10, 23, 25, 2,  19, 16, 2,  19, 28, 25, 24, 2,  2,  4,  17, 4,  12, 26, 4,  25, 31, 27, 31, 14,
      17, 13, 24, 5,  10, 10, 17, 26, 16, 15, 25, 18, 15, 10, 22, 13, 30, 16, 23, 10, 23, 24, 10, 14, 5,  17,
  };

  TransArgs args{data_5d, FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 32}, {1, 4, 4, 32}, DT_UINT8};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), SUCCESS);
  EXPECT_EQ(result.length, sizeof(data));
  for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
    EXPECT_EQ((reinterpret_cast<uint8_t *>(result.data.get()))[i], data[i]);
  }
}

TEST_F(UtestFormatTransfer5dNhwc, nc1hwc0_to_nhwc_fp16_single) {
  uint16_t data[1 * 1 * 1 * 1] = {13425};
  uint16_t data_5d[1 * 1 * 1 * 1 * 16] = {
      13425, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  };

  FormatTransferNc1hwc0Nhwc transfer;
  TransArgs args{
      reinterpret_cast<uint8_t *>(data_5d), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 1, 1, 16}, {1, 1, 1, 1}, DT_FLOAT16};

  TransResult result;
  EXPECT_EQ(transfer.TransFormat(args, result), SUCCESS);
  EXPECT_EQ(result.length, sizeof(data));
  for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
    EXPECT_EQ((reinterpret_cast<uint16_t *>(result.data.get()))[i], data[i]);
  }
}

TEST_F(UtestFormatTransfer5dNhwc, nc1hwc0_to_nhwc_fp16) {
  uint16_t data[1 * 4 * 4 * 16] = {
      15272, 12501, 13940, 10024, 13356, 13068, 12088, 13733, 15257, 14104, 11089, 15298, 10597, 14359, 14402, 14748,
      14596, 14063, 14674, 13393, 12937, 13466, 14313, 13295, 15000, 15167, 15311, 13122, 10691, 15165, 14621, 14000,
      13584, 14715, 15105, 14479, 14007, 9846,  14325, 12765, 13343, 13988, 10021, 14598, 14623, 15077, 15204, 12528,
      12024, 14236, 14857, 13009, 15216, 12916, 12754, 14807, 15174, 15075, 12998, 13834, 15174, 13674, 15251, 12683,
      13116, 14819, 11956, 14416, 14717, 14954, 15267, 15143, 15292, 9704,  14781, 14965, 14808, 15008, 11416, 15074,
      14168, 14417, 13441, 10673, 14945, 15114, 15358, 15116, 11950, 12057, 15321, 14973, 14950, 13984, 14900, 11361,
      10161, 14742, 13366, 13683, 13439, 12865, 10623, 14720, 14545, 13063, 10190, 12474, 9850,  15088, 15228, 14195,
      13428, 12443, 14719, 14816, 13231, 12818, 13667, 9680,  14814, 13924, 12757, 15178, 13444, 13673, 14405, 12711,
      15279, 14207, 9089,  13774, 13008, 14685, 13887, 15293, 13983, 14590, 15232, 15285, 15071, 14974, 15257, 13900,
      14907, 15269, 10955, 13635, 15132, 15026, 14218, 14498, 15235, 11243, 14704, 11563, 14394, 6840,  13619, 14655,
      12830, 14094, 12487, 13016, 13128, 15082, 6517,  14170, 14713, 14208, 13583, 12831, 15064, 13157, 13761, 14456,
      14905, 14798, 11391, 14668, 13906, 11053, 12381, 15210, 13567, 15159, 15270, 15073, 13887, 11861, 14615, 12627,
      15209, 14630, 13394, 14228, 14184, 13719, 14805, 13748, 14215, 13234, 13053, 14651, 14753, 14560, 12289, 14957,
      12826, 14788, 15236, 14249, 15211, 14329, 14830, 14793, 13202, 14635, 14489, 14664, 10751, 10992, 13459, 13658,
      14947, 14484, 15045, 14431, 14644, 13939, 14088, 14092, 14765, 14096, 14696, 13201, 15162, 14751, 14119, 13506,
      14659, 15355, 14904, 13374, 15048, 15188, 14733, 14307, 12518, 12511, 15187, 11018, 13072, 15023, 11355, 14216,
  };

  uint16_t data_5d[1 * 1 * 4 * 4 * 16] = {
      15272, 12501, 13940, 10024, 13356, 13068, 12088, 13733, 15257, 14104, 11089, 15298, 10597, 14359, 14402, 14748,
      14596, 14063, 14674, 13393, 12937, 13466, 14313, 13295, 15000, 15167, 15311, 13122, 10691, 15165, 14621, 14000,
      13584, 14715, 15105, 14479, 14007, 9846,  14325, 12765, 13343, 13988, 10021, 14598, 14623, 15077, 15204, 12528,
      12024, 14236, 14857, 13009, 15216, 12916, 12754, 14807, 15174, 15075, 12998, 13834, 15174, 13674, 15251, 12683,
      13116, 14819, 11956, 14416, 14717, 14954, 15267, 15143, 15292, 9704,  14781, 14965, 14808, 15008, 11416, 15074,
      14168, 14417, 13441, 10673, 14945, 15114, 15358, 15116, 11950, 12057, 15321, 14973, 14950, 13984, 14900, 11361,
      10161, 14742, 13366, 13683, 13439, 12865, 10623, 14720, 14545, 13063, 10190, 12474, 9850,  15088, 15228, 14195,
      13428, 12443, 14719, 14816, 13231, 12818, 13667, 9680,  14814, 13924, 12757, 15178, 13444, 13673, 14405, 12711,
      15279, 14207, 9089,  13774, 13008, 14685, 13887, 15293, 13983, 14590, 15232, 15285, 15071, 14974, 15257, 13900,
      14907, 15269, 10955, 13635, 15132, 15026, 14218, 14498, 15235, 11243, 14704, 11563, 14394, 6840,  13619, 14655,
      12830, 14094, 12487, 13016, 13128, 15082, 6517,  14170, 14713, 14208, 13583, 12831, 15064, 13157, 13761, 14456,
      14905, 14798, 11391, 14668, 13906, 11053, 12381, 15210, 13567, 15159, 15270, 15073, 13887, 11861, 14615, 12627,
      15209, 14630, 13394, 14228, 14184, 13719, 14805, 13748, 14215, 13234, 13053, 14651, 14753, 14560, 12289, 14957,
      12826, 14788, 15236, 14249, 15211, 14329, 14830, 14793, 13202, 14635, 14489, 14664, 10751, 10992, 13459, 13658,
      14947, 14484, 15045, 14431, 14644, 13939, 14088, 14092, 14765, 14096, 14696, 13201, 15162, 14751, 14119, 13506,
      14659, 15355, 14904, 13374, 15048, 15188, 14733, 14307, 12518, 12511, 15187, 11018, 13072, 15023, 11355, 14216,
  };

  FormatTransferNc1hwc0Nhwc transfer;
  TransArgs args{
      reinterpret_cast<uint8_t *>(data_5d), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 16}, {1, 4, 4, 16}, DT_FLOAT16};

  TransResult result;
  EXPECT_EQ(transfer.TransFormat(args, result), SUCCESS);
  EXPECT_EQ(result.length, sizeof(data));
  for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
    EXPECT_EQ((reinterpret_cast<uint16_t *>(result.data.get()))[i], data[i]);
  }
}

TEST_F(UtestFormatTransfer5dNhwc, nc1hwc0_to_nhwc_fp16_17c) {
  uint16_t data[1 * 4 * 4 * 17] = {
      13688, 13163, 15170, 12549, 12876, 15228, 14672, 14988, 13134, 14510, 9810,  15108, 14863, 13964, 13563, 12807,
      13855, 13713, 14783, 14854, 13049, 11513, 15025, 14681, 13663, 13722, 14976, 15068, 14816, 13831, 13642, 15235,
      13133, 14666, 14169, 11361, 14948, 14421, 14255, 14285, 15057, 11992, 14788, 13201, 15119, 14856, 14793, 12473,
      15215, 14789, 14728, 14311, 12980, 10457, 10908, 12896, 14619, 15085, 12907, 11787, 13731, 13228, 15259, 14651,
      13829, 12858, 14998, 13957, 15122, 13691, 13185, 11770, 13198, 12714, 15199, 13931, 9780,  14569, 15353, 14807,
      14196, 14570, 14753, 14042, 14983, 12953, 14874, 15089, 13383, 13795, 12129, 14556, 13240, 14965, 13331, 11285,
      15188, 15110, 14909, 14485, 14336, 13854, 13931, 15042, 13277, 14478, 12890, 14101, 14639, 14380, 14453, 15222,
      13431, 13650, 14330, 15188, 15118, 13645, 13878, 8366,  15192, 9233,  13516, 14812, 15289, 14551, 14772, 10564,
      13672, 14892, 11295, 15075, 15080, 14504, 11827, 15286, 13510, 13808, 10051, 12669, 15104, 14790, 15166, 12735,
      13908, 15202, 15103, 13600, 10602, 14248, 14810, 14408, 14317, 11545, 14353, 12064, 14610, 14610, 14557, 14438,
      11772, 14486, 14024, 15136, 11316, 15070, 14996, 13987, 12120, 14548, 13976, 13462, 13614, 14785, 12854, 11411,
      14179, 13944, 12796, 13491, 13781, 14549, 13506, 13369, 14249, 14973, 12837, 14507, 13462, 14467, 14856, 14851,
      14744, 15209, 12085, 13802, 13234, 15098, 12964, 14569, 15206, 11899, 11525, 15082, 14794, 14982, 14552, 15075,
      14741, 14730, 15013, 13483, 14997, 13342, 11416, 12620, 15125, 13969, 13737, 14041, 11219, 15355, 11361, 12378,
      13717, 13299, 14856, 12113, 15291, 12946, 15038, 14854, 13568, 13635, 14525, 12769, 13663, 13672, 14164, 14763,
      14661, 12871, 10567, 13383, 14679, 13331, 15247, 14464, 14642, 13930, 15218, 15040, 14614, 10533, 13511, 13577,
      12696, 11780, 11060, 15069, 11544, 15333, 15295, 14505, 11951, 12790, 14115, 14978, 12227, 14806, 15238, 14393,
  };
  uint16_t data_5d[1 * 2 * 4 * 4 * 16] = {
      13688, 13163, 15170, 12549, 12876, 15228, 14672, 14988, 13134, 14510, 9810,  15108, 14863, 13964, 13563, 12807,
      13713, 14783, 14854, 13049, 11513, 15025, 14681, 13663, 13722, 14976, 15068, 14816, 13831, 13642, 15235, 13133,
      14169, 11361, 14948, 14421, 14255, 14285, 15057, 11992, 14788, 13201, 15119, 14856, 14793, 12473, 15215, 14789,
      14311, 12980, 10457, 10908, 12896, 14619, 15085, 12907, 11787, 13731, 13228, 15259, 14651, 13829, 12858, 14998,
      15122, 13691, 13185, 11770, 13198, 12714, 15199, 13931, 9780,  14569, 15353, 14807, 14196, 14570, 14753, 14042,
      12953, 14874, 15089, 13383, 13795, 12129, 14556, 13240, 14965, 13331, 11285, 15188, 15110, 14909, 14485, 14336,
      13931, 15042, 13277, 14478, 12890, 14101, 14639, 14380, 14453, 15222, 13431, 13650, 14330, 15188, 15118, 13645,
      8366,  15192, 9233,  13516, 14812, 15289, 14551, 14772, 10564, 13672, 14892, 11295, 15075, 15080, 14504, 11827,
      13510, 13808, 10051, 12669, 15104, 14790, 15166, 12735, 13908, 15202, 15103, 13600, 10602, 14248, 14810, 14408,
      11545, 14353, 12064, 14610, 14610, 14557, 14438, 11772, 14486, 14024, 15136, 11316, 15070, 14996, 13987, 12120,
      13976, 13462, 13614, 14785, 12854, 11411, 14179, 13944, 12796, 13491, 13781, 14549, 13506, 13369, 14249, 14973,
      14507, 13462, 14467, 14856, 14851, 14744, 15209, 12085, 13802, 13234, 15098, 12964, 14569, 15206, 11899, 11525,
      14794, 14982, 14552, 15075, 14741, 14730, 15013, 13483, 14997, 13342, 11416, 12620, 15125, 13969, 13737, 14041,
      15355, 11361, 12378, 13717, 13299, 14856, 12113, 15291, 12946, 15038, 14854, 13568, 13635, 14525, 12769, 13663,
      14164, 14763, 14661, 12871, 10567, 13383, 14679, 13331, 15247, 14464, 14642, 13930, 15218, 15040, 14614, 10533,
      13577, 12696, 11780, 11060, 15069, 11544, 15333, 15295, 14505, 11951, 12790, 14115, 14978, 12227, 14806, 15238,
      13855, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      14666, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      14728, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      13957, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      14983, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      13854, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      13878, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      15286, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      14317, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      14548, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      12837, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      15082, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      11219, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      13672, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      13511, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      14393, 0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  };
  FormatTransferNc1hwc0Nhwc transfer;
  TransArgs args{
      reinterpret_cast<uint8_t *>(data_5d), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 2, 4, 4, 16}, {1, 4, 4, 17}, DT_FLOAT16};

  TransResult result;
  EXPECT_EQ(transfer.TransFormat(args, result), SUCCESS);
  EXPECT_EQ(result.length, sizeof(data));
  for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
    EXPECT_EQ((reinterpret_cast<uint16_t *>(result.data.get()))[i], data[i]);
  }
}

TEST_F(UtestFormatTransfer5dNhwc, nc1hwc0_to_nhwc_float) {
  float data[1 * 4 * 4 * 8] = {
      0.14395748132615127,  0.7088975015001723,   0.33509522683279236,  0.519409599070846,     0.6877815703183492,
      0.11202024034801872,  0.006276379581528935, 0.3691877050360296,   0.8286682894080306,    0.8577776441477236,
      0.8620479285149965,   0.4785995315212451,   0.44290479161201646,  0.9298880355625483,    0.2079760936942212,
      0.7584010867023864,   0.04130212504113229,  0.6886546611913413,   0.8905605080864101,    0.44890343542909616,
      0.033926825396621396, 0.5658782347882929,   0.0154316787055232,   0.6715229410700493,    0.15104032692043634,
      0.7987494899164227,   0.4107814620344469,   0.2739026396531693,   0.78314190163481,      0.5572462878749022,
      0.49687645697979144,  0.2610836567590066,   0.662984178264575,    0.8272197084584877,    0.951921638821051,
      0.22020310043156965,  0.7970234862803476,   0.786770080635131,    0.2782844900661975,    0.2214492309528462,
      0.05973945191243013,  0.7787265114728507,   0.5885108317539937,   0.6350434845578384,    0.03432358265902924,
      0.13814464833713236,  0.47716000964132366,  0.2172979558296817,   0.28184686482223664,   0.023912988786341294,
      0.564989222222373,    0.6350727555041364,   0.17406682486362202,  0.5782687973077343,    0.7691109852619834,
      0.6283233021413348,   0.7351740165991039,   0.3215521304014334,   0.6774009330532079,    0.33739099291474717,
      0.9568828717913317,   0.00406630044661338,  0.022773887476273513, 0.0062475315550286625, 0.11386475535418572,
      0.31803152343086083,  0.5060149804451273,   0.9748224337922627,   0.08021564523597269,   0.36955307731376397,
      0.45745050755121797,  0.6991568446588684,   0.48452855411290163,  0.1687682253709446,    0.8171081226272253,
      0.5722562245860371,   0.38631439575235693,  0.4152775169941805,   0.5471240543016923,    0.47255359909361083,
      0.19979061254107167,  0.6128813529241708,   0.23241802167600212,  0.6598280464895825,    0.39993127352459,
      0.6179092276151944,   0.3842495249973191,   0.07172557002264568,  0.5232161572150006,    0.33507445318217577,
      0.6669179668737779,   0.5710568144146737,   0.09743181036899662,  0.1960181228757637,    0.024614338703409122,
      0.04305198418453349,  0.8272287766449594,   0.3104293133165287,   0.295404336140902,     0.869972288744926,
      0.6598182869917978,   0.1256465164983911,   0.6611169004945606,   0.887335228528663,     0.30319799367763645,
      0.10221678669180034,  0.822023968653782,    0.7054515545991238,   0.7026671130911287,    0.6583675813685899,
      0.14794276026959252,  0.12379423708188408,  0.010717044340432524, 0.3335554745873852,    0.6960727743111309,
      0.835599614916433,    0.6695589997837782,   0.928169629281005,    0.2751019740519224,    0.09543122169280194,
      0.5117813618227156,   0.33444700996623,     0.5634565397240759,   0.5205229823558587,    0.7650601279838857,
      0.517468037811738,    0.5880785947369374,   0.2177496979194814,
  };
  float data_5d[1 * 1 * 4 * 4 * 16] = {
      0.14395748132615127,
      0.7088975015001723,
      0.33509522683279236,
      0.519409599070846,
      0.6877815703183492,
      0.11202024034801872,
      0.006276379581528935,
      0.3691877050360296,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.8286682894080306,
      0.8577776441477236,
      0.8620479285149965,
      0.4785995315212451,
      0.44290479161201646,
      0.9298880355625483,
      0.2079760936942212,
      0.7584010867023864,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.04130212504113229,
      0.6886546611913413,
      0.8905605080864101,
      0.44890343542909616,
      0.033926825396621396,
      0.5658782347882929,
      0.0154316787055232,
      0.6715229410700493,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.15104032692043634,
      0.7987494899164227,
      0.4107814620344469,
      0.2739026396531693,
      0.78314190163481,
      0.5572462878749022,
      0.49687645697979144,
      0.2610836567590066,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.662984178264575,
      0.8272197084584877,
      0.951921638821051,
      0.22020310043156965,
      0.7970234862803476,
      0.786770080635131,
      0.2782844900661975,
      0.2214492309528462,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.05973945191243013,
      0.7787265114728507,
      0.5885108317539937,
      0.6350434845578384,
      0.03432358265902924,
      0.13814464833713236,
      0.47716000964132366,
      0.2172979558296817,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.28184686482223664,
      0.023912988786341294,
      0.564989222222373,
      0.6350727555041364,
      0.17406682486362202,
      0.5782687973077343,
      0.7691109852619834,
      0.6283233021413348,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.7351740165991039,
      0.3215521304014334,
      0.6774009330532079,
      0.33739099291474717,
      0.9568828717913317,
      0.00406630044661338,
      0.022773887476273513,
      0.0062475315550286625,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.11386475535418572,
      0.31803152343086083,
      0.5060149804451273,
      0.9748224337922627,
      0.08021564523597269,
      0.36955307731376397,
      0.45745050755121797,
      0.6991568446588684,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.48452855411290163,
      0.1687682253709446,
      0.8171081226272253,
      0.5722562245860371,
      0.38631439575235693,
      0.4152775169941805,
      0.5471240543016923,
      0.47255359909361083,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.19979061254107167,
      0.6128813529241708,
      0.23241802167600212,
      0.6598280464895825,
      0.39993127352459,
      0.6179092276151944,
      0.3842495249973191,
      0.07172557002264568,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.5232161572150006,
      0.33507445318217577,
      0.6669179668737779,
      0.5710568144146737,
      0.09743181036899662,
      0.1960181228757637,
      0.024614338703409122,
      0.04305198418453349,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.8272287766449594,
      0.3104293133165287,
      0.295404336140902,
      0.869972288744926,
      0.6598182869917978,
      0.1256465164983911,
      0.6611169004945606,
      0.887335228528663,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.30319799367763645,
      0.10221678669180034,
      0.822023968653782,
      0.7054515545991238,
      0.7026671130911287,
      0.6583675813685899,
      0.14794276026959252,
      0.12379423708188408,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.010717044340432524,
      0.3335554745873852,
      0.6960727743111309,
      0.835599614916433,
      0.6695589997837782,
      0.928169629281005,
      0.2751019740519224,
      0.09543122169280194,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.5117813618227156,
      0.33444700996623,
      0.5634565397240759,
      0.5205229823558587,
      0.7650601279838857,
      0.517468037811738,
      0.5880785947369374,
      0.2177496979194814,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
  };

  FormatTransferNc1hwc0Nhwc transfer;
  TransArgs args{
      reinterpret_cast<uint8_t *>(data_5d), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 16}, {1, 4, 4, 8}, DT_FLOAT};
  TransResult result;
  EXPECT_EQ(transfer.TransFormat(args, result), SUCCESS);
  EXPECT_EQ(result.length, sizeof(data));
  for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
    EXPECT_FLOAT_EQ((reinterpret_cast<float *>(result.data.get()))[i], data[i]);
  }
}

TEST_F(UtestFormatTransfer5dNhwc, nc1hwc0_to_nhwc_float2) {
  float data[1 * 4 * 4 * 16] = {
      0.4564786036237277,  0.9979708631827585,   0.3433449574519194,   0.8327170836954324,   0.7102312568870411,
      0.4620266296757265,  0.731409804774576,    0.6657620022925489,   0.9035335884051056,   0.9985587438582897,
      0.9914301800355473,  0.7964115237958334,   0.8584244270496925,   0.1378300681142447,   0.9146423401653642,
      0.5838660267355298,  0.08206209108887697,  0.5978772929814459,   0.8606477151292675,   0.9621549085527097,
      0.9903169628823607,  0.4413502878053672,   0.3419319864126722,   0.2055590347352939,   0.6958247381061989,
      0.31025181192729134, 0.8754696913785533,   0.16342168578297833,  0.48930764038405494,  0.4313174744262651,
      0.9702299296220505,  0.8608633387702506,   0.32414390364635537,  0.9499311305911101,   0.16162894064122346,
      0.7903673191014232,  0.9747281169251742,   0.19047786660677712,  0.5261388562183582,   0.08832658004278726,
      0.5026034609888064,  0.6012786562129157,   0.22023272766428525,  0.020620813194720755, 0.05621537431872736,
      0.9065752732717621,  0.10241901312343715,  0.7468164462101752,   0.6025800857266902,   0.8563704540567573,
      0.06781353150900471, 0.07449933352495186,  0.6462834271091005,   0.6443763466531751,   0.23443689347408292,
      0.9007764794631198,  0.2654578696798139,   0.34714459047552515,  0.9442670098376124,   0.6551617300899828,
      0.18577821984901555, 0.6554056318808226,   0.9256976155576719,   0.5652951773970069,   0.9036782198563219,
      0.4044957431656302,  0.7720355215505535,   0.9615844951249943,   0.9583990983695638,   0.6734156011463083,
      0.07600462174220979, 0.6483143942496717,   0.7721284471233,      0.8844698574851142,   0.36446559980424187,
      0.2020712252813367,  0.5532440010466321,   0.774082923402127,    0.15753243710488063,  0.7494487845016365,
      0.9777126596615223,  0.5977366091149126,   0.6118678708384551,   0.5776021887764191,   0.7052275323758874,
      0.8643536179940521,  0.7351423461892231,   0.7472712957396752,   0.8320997849162026,   0.6893202120458873,
      0.6061132885338082,  0.7922244558608248,   0.0694183157723195,   0.46637306821083124,  0.24761782321363746,
      0.841220929773547,   0.19251486945606122,  0.38619121136754864,  0.7777480845728865,   0.5153172040040658,
      0.3221852259862178,  0.4422626646996969,   0.37297798349444533,  0.28636326416033275,  0.872322772220719,
      0.36684031320178934, 0.19151281097764805,  0.011093279580771997, 0.4565429665149845,   0.33857376446626597,
      0.3893706571125203,  0.09763853688754631,  0.7857370586828217,   0.8196400350274258,   0.6233161446810015,
      0.7290476585781567,  0.32302816180960103,  0.6465065602583131,   0.7039055178319722,   0.737269028941926,
      0.4423557810299573,  0.2936287529863649,   0.17383709070689168,  0.07431649542543162,  0.3395265133684905,
      0.6974196233605686,  0.029369533449977392, 0.8462674586537903,   0.1862823571798382,   0.7055362309875918,
      0.17654051410721183, 0.6964155103280214,   0.8712303990874309,   0.8568724052794551,   0.12588302504561832,
      0.7811576698822645,  0.4767670325567058,   0.6159667262200001,   0.05490717393005784,  0.6057928538737336,
      0.8546815077994012,  0.35062523335992557,  0.12129862795339719,  0.26548933441616984,  0.7385743748060322,
      0.40555441839717865, 0.9982561364349957,   0.3188263567371774,   0.9424891762411117,   0.6987901399365776,
      0.20540961831616766, 0.02167040277535437,  0.3185967031398763,   0.019782643683121437, 0.8438032683953371,
      0.31134590764527503, 0.4314797108424774,   0.8627081052949851,   0.8372865189589538,   0.06727616337496733,
      0.3842235730532829,  0.5620567599469514,   0.4872978433211791,   0.6475139880108287,   0.415262171705042,
      0.16946425200394755, 0.37100485677595374,  0.5675133342481045,   0.39388891080376875,  0.11961877709354252,
      0.6050560699851201,  0.6113694663807391,   0.7148151069557451,   0.3227410199494769,   0.47070000531233336,
      0.6184325422121354,  0.9366505496068971,   0.044456665466675815, 0.6052379671242412,   0.0566508245272247,
      0.293920203298791,   0.13061352402232362,  0.11203690960569768,  0.8258966037746421,   0.2946765132214273,
      0.8466489444530028,  0.7451823806430503,   0.15781221269704837,  0.4021853233314594,   0.664241200519387,
      0.7091761574997846,  0.7412572946122742,   0.12408378577361201,  0.6351997345547254,   0.49923734082324256,
      0.7532652811776691,  0.4831886413654197,   0.8560909415971528,   0.5359252954295073,   0.27940116425452954,
      0.697831712634371,   0.6651941742331731,   0.38894273544941194,  0.6511702859506332,   0.24281567468797605,
      0.28501013033328104, 0.4337819166171949,   0.5961407181707284,   0.5496662828770404,   0.41579648284745674,
      0.8751091806383153,  0.20914271806373042,  0.5223981065749688,   0.36853485871088787,  0.6950926163206822,
      0.8626788290432134,  0.280786741801478,    0.9968042088585791,   0.047574943064607855, 0.3553705848433375,
      0.8500631428597956,  0.7900997773399084,   0.08208295892311868,  0.5799468056312337,   0.8678034851684076,
      0.6620161902490288,  0.10118441445571336,  0.5346674104167647,   0.46546006518032723,  0.7854958793456643,
      0.41889328134628867, 0.4788457107828109,   0.5693837686243997,   0.03982329678460883,  0.5036591611514133,
      0.8634869905751454,  0.36418146420377306,  0.3560197611754259,   0.4237274215048007,   0.9272113781908002,
      0.4733639065953018,  0.11277189215022076,  0.46944385729018046,  0.5240510466702447,   0.3809929220315893,
      0.9044904830984387,  0.630375764858229,    0.40395182381843286,  0.39508838980681005,  0.762649660569511,
      0.7194310117846976,  0.992973488796045,    0.22591279583891666,  0.4331673497772569,   0.6014661361937058,
      0.7590490257651524,
  };
  float data_5d[1 * 1 * 4 * 4 * 16] = {
      0.4564786036237277,  0.9979708631827585,   0.3433449574519194,   0.8327170836954324,   0.7102312568870411,
      0.4620266296757265,  0.731409804774576,    0.6657620022925489,   0.9035335884051056,   0.9985587438582897,
      0.9914301800355473,  0.7964115237958334,   0.8584244270496925,   0.1378300681142447,   0.9146423401653642,
      0.5838660267355298,  0.08206209108887697,  0.5978772929814459,   0.8606477151292675,   0.9621549085527097,
      0.9903169628823607,  0.4413502878053672,   0.3419319864126722,   0.2055590347352939,   0.6958247381061989,
      0.31025181192729134, 0.8754696913785533,   0.16342168578297833,  0.48930764038405494,  0.4313174744262651,
      0.9702299296220505,  0.8608633387702506,   0.32414390364635537,  0.9499311305911101,   0.16162894064122346,
      0.7903673191014232,  0.9747281169251742,   0.19047786660677712,  0.5261388562183582,   0.08832658004278726,
      0.5026034609888064,  0.6012786562129157,   0.22023272766428525,  0.020620813194720755, 0.05621537431872736,
      0.9065752732717621,  0.10241901312343715,  0.7468164462101752,   0.6025800857266902,   0.8563704540567573,
      0.06781353150900471, 0.07449933352495186,  0.6462834271091005,   0.6443763466531751,   0.23443689347408292,
      0.9007764794631198,  0.2654578696798139,   0.34714459047552515,  0.9442670098376124,   0.6551617300899828,
      0.18577821984901555, 0.6554056318808226,   0.9256976155576719,   0.5652951773970069,   0.9036782198563219,
      0.4044957431656302,  0.7720355215505535,   0.9615844951249943,   0.9583990983695638,   0.6734156011463083,
      0.07600462174220979, 0.6483143942496717,   0.7721284471233,      0.8844698574851142,   0.36446559980424187,
      0.2020712252813367,  0.5532440010466321,   0.774082923402127,    0.15753243710488063,  0.7494487845016365,
      0.9777126596615223,  0.5977366091149126,   0.6118678708384551,   0.5776021887764191,   0.7052275323758874,
      0.8643536179940521,  0.7351423461892231,   0.7472712957396752,   0.8320997849162026,   0.6893202120458873,
      0.6061132885338082,  0.7922244558608248,   0.0694183157723195,   0.46637306821083124,  0.24761782321363746,
      0.841220929773547,   0.19251486945606122,  0.38619121136754864,  0.7777480845728865,   0.5153172040040658,
      0.3221852259862178,  0.4422626646996969,   0.37297798349444533,  0.28636326416033275,  0.872322772220719,
      0.36684031320178934, 0.19151281097764805,  0.011093279580771997, 0.4565429665149845,   0.33857376446626597,
      0.3893706571125203,  0.09763853688754631,  0.7857370586828217,   0.8196400350274258,   0.6233161446810015,
      0.7290476585781567,  0.32302816180960103,  0.6465065602583131,   0.7039055178319722,   0.737269028941926,
      0.4423557810299573,  0.2936287529863649,   0.17383709070689168,  0.07431649542543162,  0.3395265133684905,
      0.6974196233605686,  0.029369533449977392, 0.8462674586537903,   0.1862823571798382,   0.7055362309875918,
      0.17654051410721183, 0.6964155103280214,   0.8712303990874309,   0.8568724052794551,   0.12588302504561832,
      0.7811576698822645,  0.4767670325567058,   0.6159667262200001,   0.05490717393005784,  0.6057928538737336,
      0.8546815077994012,  0.35062523335992557,  0.12129862795339719,  0.26548933441616984,  0.7385743748060322,
      0.40555441839717865, 0.9982561364349957,   0.3188263567371774,   0.9424891762411117,   0.6987901399365776,
      0.20540961831616766, 0.02167040277535437,  0.3185967031398763,   0.019782643683121437, 0.8438032683953371,
      0.31134590764527503, 0.4314797108424774,   0.8627081052949851,   0.8372865189589538,   0.06727616337496733,
      0.3842235730532829,  0.5620567599469514,   0.4872978433211791,   0.6475139880108287,   0.415262171705042,
      0.16946425200394755, 0.37100485677595374,  0.5675133342481045,   0.39388891080376875,  0.11961877709354252,
      0.6050560699851201,  0.6113694663807391,   0.7148151069557451,   0.3227410199494769,   0.47070000531233336,
      0.6184325422121354,  0.9366505496068971,   0.044456665466675815, 0.6052379671242412,   0.0566508245272247,
      0.293920203298791,   0.13061352402232362,  0.11203690960569768,  0.8258966037746421,   0.2946765132214273,
      0.8466489444530028,  0.7451823806430503,   0.15781221269704837,  0.4021853233314594,   0.664241200519387,
      0.7091761574997846,  0.7412572946122742,   0.12408378577361201,  0.6351997345547254,   0.49923734082324256,
      0.7532652811776691,  0.4831886413654197,   0.8560909415971528,   0.5359252954295073,   0.27940116425452954,
      0.697831712634371,   0.6651941742331731,   0.38894273544941194,  0.6511702859506332,   0.24281567468797605,
      0.28501013033328104, 0.4337819166171949,   0.5961407181707284,   0.5496662828770404,   0.41579648284745674,
      0.8751091806383153,  0.20914271806373042,  0.5223981065749688,   0.36853485871088787,  0.6950926163206822,
      0.8626788290432134,  0.280786741801478,    0.9968042088585791,   0.047574943064607855, 0.3553705848433375,
      0.8500631428597956,  0.7900997773399084,   0.08208295892311868,  0.5799468056312337,   0.8678034851684076,
      0.6620161902490288,  0.10118441445571336,  0.5346674104167647,   0.46546006518032723,  0.7854958793456643,
      0.41889328134628867, 0.4788457107828109,   0.5693837686243997,   0.03982329678460883,  0.5036591611514133,
      0.8634869905751454,  0.36418146420377306,  0.3560197611754259,   0.4237274215048007,   0.9272113781908002,
      0.4733639065953018,  0.11277189215022076,  0.46944385729018046,  0.5240510466702447,   0.3809929220315893,
      0.9044904830984387,  0.630375764858229,    0.40395182381843286,  0.39508838980681005,  0.762649660569511,
      0.7194310117846976,  0.992973488796045,    0.22591279583891666,  0.4331673497772569,   0.6014661361937058,
      0.7590490257651524,
  };

  FormatTransferNc1hwc0Nhwc transfer;
  TransArgs args{
      reinterpret_cast<uint8_t *>(data_5d), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 16}, {1, 4, 4, 16}, DT_FLOAT};
  TransResult result;
  EXPECT_EQ(transfer.TransFormat(args, result), SUCCESS);
  EXPECT_EQ(result.length, sizeof(data));
  for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
    EXPECT_FLOAT_EQ((reinterpret_cast<float *>(result.data.get()))[i], data[i]);
  }
  Status status =
      transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape);
  EXPECT_EQ(status, UNSUPPORTED);
}

TEST_F(UtestFormatTransfer5dNhwc, invalid_src_format) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_RESERVED, FORMAT_NHWC, {1, 1, 4, 4, 16}, {1, 4, 4, 1}, DT_FLOAT16};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}

TEST_F(UtestFormatTransfer5dNhwc, invalid_src_shape1) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 16, 1}, {1, 4, 4, 1}, DT_FLOAT16};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}

TEST_F(UtestFormatTransfer5dNhwc, InvalidSrcShape2) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_NC1HWC0, FORMAT_NHWC, {1, -1, 4, 4, 16}, {1, 4, 4, 1}, DT_FLOAT16};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}

TEST_F(UtestFormatTransfer5dNhwc, invalid_src_data_type) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_NC1HWC0, FORMAT_NHWC, {1, -1, 4, 4, 16}, {1, 4, 4, 1}, DT_UNDEFINED};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}

TEST_F(UtestFormatTransfer5dNhwc, invalid_dst_format) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_NC1HWC0, FORMAT_NCHW, {1, 1, 4, 4, 16}, {1, 4, 4, 1}, DT_FLOAT16};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}

TEST_F(UtestFormatTransfer5dNhwc, invalid_dst_shape1) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 16}, {1, 4, 4}, DT_FLOAT16};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}

TEST_F(UtestFormatTransfer5dNhwc, invalid_dst_shape2) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 16}, {1, 4, 4, -1}, DT_FLOAT16};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}

TEST_F(UtestFormatTransfer5dNhwc, invalid_src_dst_shape_relation) {
  uint16_t data[1 * 1 * 4 * 4 * 16] = {0};
  TransArgs args{
      reinterpret_cast<uint8_t *>(data), FORMAT_NC1HWC0, FORMAT_NHWC, {1, 1, 4, 4, 16}, {1, 4, 4, 17}, DT_FLOAT16};
  TransResult result;

  FormatTransferNc1hwc0Nhwc transfer;
  EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID);
}
}  // namespace formats
}  // namespace ge